package com.neusoft.control;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.neusoft.bean.AdminInfoBean;
import com.neusoft.myutils.MyUtil;
import com.neusoft.service.AdminLoginService;

/**
 * 
 */
@WebServlet("/AdminLoginedServlet")
public class AdminLoginedServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * 登录页面的转发控制
	 */
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//使用request请求获取表单数据
		String strAdminName = request.getParameter("adminName");
		String strAdminPsw = request.getParameter("adminPsw");
		//调用工具类的方法创建bean实例对象
		AdminInfoBean aib = MyUtil.getInstance(AdminInfoBean.class);
		//利用bean实体对象传值
		aib.setAdminName(strAdminName);
		aib.setAdminPsw(strAdminPsw);
		List<AdminInfoBean> adminLst = MyUtil.getInstance(AdminLoginService.class).doAdminLogined(aib);
		if (adminLst !=null && adminLst.size()>0) {
			request.getSession().setAttribute("adminLst", adminLst);
			request.getRequestDispatcher("Logined/logined.jsp").forward(request, response);
		} else {
			response.sendRedirect("login.jsp");
		}
	}

}
